package Login.servlet;

import Login.Service.BookService;
import Login.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet(name = "bookServlet",urlPatterns = "/list")
public class bookServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            BookService bookService = new BookService();
            if (!bookService.hasSession(req.getSession(), resp)) {
                return;
            }
            ArrayList<Book> books = bookService.getBookList();
            req.setAttribute("list", books);
            req.getRequestDispatcher("bookList.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
